<script setup lang='ts'>
  import { reactive, ref, shallowRef, nextTick } from 'vue';
  import roomlist from './roomlist.vue';
  import userlist from './userlist.vue';
  import wealthlist from './wealthlist.vue';
  import unionForm from './unionForm.vue';
  const $emit = defineEmits(["updateList"]);
  const unionFormDom = shallowRef(),
  componentRef = ref();
  const action = reactive({
    drawerDialog:false,
    title:''
  })
  let unionObj = {}
  const handleDialog = (comp:any = {},formType:number = 0)=>{
    unionFormDom.value = comp
    nextTick(()=>{
      if(formType) {
        componentRef.value.openDialog({
          ...unionObj,
          formType
        })
      }
      else {
        componentRef.value.openDialog(unionObj)
      }
    })
  }
  const updateList = ()=>{
    action.drawerDialog = false
    $emit('updateList')
  }
  const openDialog = (row:any = {})=>{
    action.drawerDialog = true
    const { name='' } = row
    action.title = `公会：${name}`
    unionObj = row
  }
  defineExpose({
    openDialog
  })
</script>

<template>
  <div>
    <el-drawer
      v-model="action.drawerDialog"
      :title="action.title"
      direction="rtl"
      class="drawerDialog"
    >
      <el-row>
        <el-col :span="8">
          <el-button type="primary" @click="handleDialog(roomlist)">公会房间</el-button>
        </el-col>
        <el-col :span="8">
          <el-button type="primary" @click="handleDialog(userlist)">公会成员</el-button>
        </el-col>
        <el-col :span="8">
          <el-button type="primary" @click="handleDialog(wealthlist)">公会流水</el-button>
        </el-col>
        <el-col :span="8">
          <el-button v-rule="'unionSetRewardType'" type="primary" @click="handleDialog(unionForm,7)">奖励类型</el-button>
        </el-col>
      </el-row>
    </el-drawer>
    <component :is="unionFormDom" ref="componentRef" @update-list="updateList"></component>
  </div>
</template>

<style lang='scss' scoped>
  :deep(.drawerDialog) {
    .el-col {
      margin-bottom: 10px;
    }
  }
</style>